// miniprogram/rember1/r1-index/index.js
let api = require('../../utils/api.js')
let myrequest = require('../../utils/myRequest.js')
let bindnav = require('../../utils/path.js') //引入路径缩写
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner:[],  //swiper数据
    brandList:[], //品牌列表
    channel:[], //频道
    hotGoodsList:[], //热门商品列表
    newGoodsList:[], //新品列表
    topicList:[],  //专题列表
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    myrequest.myRequest({
      url: api.index,
      success: (res) => {
        // 获取各项数据并填入data
        console.log(res)
        let data = res.data.data;
        let banner = data.banner;
        let brandList = data.brandList;
        let channel = data.channel;
        let hotGoodsList = data.hotGoodsList;
        let newGoodsList = data.newGoodsList;
        let topicList = data.topicList;
        this.setData({
          banner: banner,
          brandList: brandList,
          channel : channel,
          hotGoodsList : hotGoodsList,
          newGoodsList : newGoodsList,
          topicList: topicList
        })
      }
    })

    myrequest.myRequest({
      url: api.search,
      success: (res) => {
        // 获取各项数据并填入data
        console.log(res)
        let data = res.data.data;
        let defaultKeyword = data.defaultKeyword;

        this.setData({
          defaultKeyword: defaultKeyword.keyword
        })

      }
    })
    
  },

  // 引入path的bindnav
  bindnav: bindnav,
  // 搜索框聚焦时弹出搜索相关内容
  searchtoaster(e){
    console.log('获得焦点')
  },
  // 搜索框失去焦点时隐藏
  hiddentoaster(e){
    console.log('失去焦点')
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})